package com.shj.controller;

import com.shj.entity.SysPart;
import com.shj.service.SysPartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author songhuajian
 * @Description: TODO
 * @date 2020/6/16 14:04
 **/
@Controller
@RequestMapping("/system/part")
public class SysPartController {

    @Autowired
    private SysPartService sysPartService;

    @RequestMapping("/list")
    public String findAll(Model model) {
        List<SysPart> list = sysPartService.findAll();
        model.addAttribute("list", list);
        return "part/part_list";
    }

    @RequestMapping("/openAdd")
    public String openAdd(Model model) {
        return "part/part_add";
    }

    @RequestMapping("/add")
    public String add(Model model, SysPart sysPart) {
        sysPartService.add(sysPart);
        return findAll(model);
    }

    @RequestMapping("/openEdit")
    public String openEdit(Model model, Integer id) {
        SysPart sysPart = sysPartService.findById(id);
        model.addAttribute("part", sysPart);
        return "part/part_edit";
    }

    @RequestMapping("/edit")
    public String edit(Model model, SysPart sysPart) {
        sysPartService.edit(sysPart);
        return findAll(model);
    }

    @RequestMapping("delete")
    public String delete(Model model, Integer id) {
        sysPartService.delete(id);
        return findAll(model);
    }
}
